﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:userControls="clr-namespace:VH.UI.UserControls;assembly=VH.UI.UserControls"
                    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
                    xmlns:controls="clr-namespace:VH.UI.UserControls.Controls;assembly=VH.UI.UserControls"
                    xmlns:converters="clr-namespace:VH.View.Converters">
    <ControlTemplate x:Key="errorTemplateSilverlightStyle">
        <StackPanel Orientation="Horizontal">
            <Border BorderThickness="1" BorderBrush="#FFdc000c" CornerRadius="0.7"
                VerticalAlignment="Top">
                <Grid>
                    <Polygon x:Name="toolTipCorner"
                         Grid.ZIndex="2"
                         Margin="-1"
                         Points="6,6 6,0 0,0" 
                         Fill="#FFdc000c" 
                         HorizontalAlignment="Right" 
                         VerticalAlignment="Top"
                         IsHitTestVisible="True"/>
                    <Polyline Grid.ZIndex="3"
                          Points="7,7 0,0" Margin="-1" HorizontalAlignment="Right" 
                          StrokeThickness="1.5"
                          StrokeEndLineCap="Round"
                          StrokeStartLineCap="Round"
                          Stroke="White"
                          VerticalAlignment="Top"
                          IsHitTestVisible="True"/>
                    <AdornedElementPlaceholder x:Name="adorner"/>
                </Grid>
            </Border>
            <Border x:Name="errorBorder" Background="#FFdc000c" Margin="1,0,0,0"
                Opacity="0" CornerRadius="1.5"
                IsHitTestVisible="False"
                MinHeight="24" MaxWidth="267">
                <!--<Border.Effect>
                    <DropShadowEffect ShadowDepth="2.25" 
                                  Color="Black" 
                                  Opacity="0.4"
                                  Direction="315"
                                  BlurRadius="4"/>
                </Border.Effect>-->
                <TextBlock Foreground="{StaticResource WhiteColorBrush}" FontWeight="SemiBold" MaxWidth="250" Margin="8,4,8,4" TextWrapping="Wrap" Text="{Binding ElementName=adorner,
                                      Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" UseLayoutRounding="false"/>
            </Border>
        </StackPanel>
        <ControlTemplate.Triggers>
            <DataTrigger Value="True">
                <DataTrigger.Binding>
                    <MultiBinding Converter="{converters:BooleanOrConverter}">
                        <Binding ElementName="adorner" Path="AdornedElement.IsKeyboardFocused" />
                        <Binding ElementName="toolTipCorner" Path="IsMouseOver"/>
                    </MultiBinding>
                </DataTrigger.Binding>
                <DataTrigger.EnterActions>
                    <BeginStoryboard x:Name="fadeInStoryboard">
                        <Storyboard>
                            <DoubleAnimation Duration="00:00:00.15"
                                         Storyboard.TargetName="errorBorder"
                                         Storyboard.TargetProperty="Opacity"
                                         To="1"/>
                            <ThicknessAnimation Duration="00:00:00.15"
                                            Storyboard.TargetName="errorBorder"
                                            Storyboard.TargetProperty="Margin"
                                            FillBehavior="HoldEnd"
                                            From="1,0,0,0"
                                            To="5,0,0,0">
                                <ThicknessAnimation.EasingFunction>
                                    <BackEase EasingMode="EaseOut" Amplitude="2"/>
                                </ThicknessAnimation.EasingFunction>
                            </ThicknessAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <DataTrigger.ExitActions>
                    <StopStoryboard BeginStoryboardName="fadeInStoryboard"/>
                    <BeginStoryboard x:Name="fadeOutStoryBoard">
                        <Storyboard>
                            <DoubleAnimation Duration="00:00:00"
                                         Storyboard.TargetName="errorBorder"
                                         Storyboard.TargetProperty="Opacity"
                                         To="0"/>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.ExitActions>
            </DataTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <Style TargetType="{x:Type userControls:AutoCompleteTextBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBox
                            x:Name="PART_txtSerach"
                            Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource TemplatedParent}, FallbackValue=''}"
                            HorizontalAlignment="{Binding HorizontalAlignment, RelativeSource={RelativeSource TemplatedParent}}"
                            Width="{Binding Width, RelativeSource={RelativeSource TemplatedParent}}"
                            Height="{Binding Height, RelativeSource={RelativeSource TemplatedParent}}"
                            Margin="{Binding Margin, RelativeSource={RelativeSource TemplatedParent}}">
                            <i:Interaction.Behaviors>
                                <userControls:TextBoxWatermarkBehavior
                                    Label="{Binding WaterMarkerText, RelativeSource={RelativeSource TemplatedParent}}"
                                    LabelStyle="{Binding WaterMarkerStyle, RelativeSource={RelativeSource TemplatedParent}}" />
                            </i:Interaction.Behaviors>
                        </TextBox>

                        <Popup
                            x:Name="PART_popup"
                            IsOpen="{Binding IsPopupOpen, RelativeSource={RelativeSource TemplatedParent}}"
                            AllowsTransparency="True"
                            PlacementTarget="{Binding ElementName=PART_txtSerach}"
                            Placement="Bottom"
                            Width="{Binding ElementName=PART_txtSerach, Path=ActualWidth}"
                            StaysOpen="False"
                            MaxHeight="{Binding PopupMaxHeight, RelativeSource={RelativeSource TemplatedParent}}">

                            <Border BorderBrush="{StaticResource AccentColorBlueBrush}" BorderThickness="1">
                                <ListBox
                                    BorderThickness="0"
                                    BorderBrush="{x:Null}"
                                    x:Name="PART_ListSearchResult"
                                    ItemsSource="{Binding SearchResultCollection, RelativeSource={RelativeSource TemplatedParent}}"
                                    SelectedItem="{Binding SelectedItem,  RelativeSource={RelativeSource TemplatedParent}}"
                                    DisplayMemberPath="{Binding DisplayMemberPath, RelativeSource={RelativeSource TemplatedParent}}"
                                    SelectedValue="{Binding SelectedValue, RelativeSource={RelativeSource TemplatedParent}}"
                                    SelectedValuePath="{Binding SelectedValuePath, RelativeSource={RelativeSource TemplatedParent}}"
                                    ItemTemplate="{Binding ListBoxItemTemplate, RelativeSource={RelativeSource TemplatedParent}}">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="MouseDoubleClick">
                                            <cmd:EventToCommand
                                                Command="{Binding ItemDoubleClickCommand, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </ListBox>
                            </Border>
                        </Popup>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="TimeItemStyle" TargetType="ListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border Name="Border" SnapsToDevicePixels="true">
                        <ContentPresenter Margin="4" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="Border" Property="Background"
                                    Value="{StaticResource HighlightLightBrush}" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="Border" Property="Background"
                                    Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                            <Setter Property="Foreground" Value="White" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type controls:TimePicker}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:TimePicker}">
                    <Border>
                        <Grid>
                            <Grid.Resources>
                                <userControls:BoolToOppositeBoolConverter x:Key="BoolToOppositeBoolConverter" />
                                <Style x:Key="ToggleButtonTemplate"  TargetType="{x:Type ToggleButton}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ToggleButton">
                                                <Grid Background="Transparent">
                                                    <Grid x:Name="grid" Background="Transparent" Margin="{TemplateBinding Padding}" >
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="Auto" />
                                                            <ColumnDefinition />
                                                        </Grid.ColumnDefinitions>

                                                        <Grid Width="18" Height="18">
                                                            <Ellipse x:Name="ellipse"
                                     Stroke="{DynamicResource ModernButtonBorder}"
                                     StrokeThickness="1"
                                     VerticalAlignment="Stretch" />
                                                            <Path x:Name="icon"
                                  Data="F1 M 42,19.0002L 34,19.0002L 34,43.7502L 24,33.7502L 24,44.2502L 38,58.2502L 52,44.2502L 52,33.7502L 42,43.7502L 42,19.0002 Z " 
                                  Width="10"
                                  Height="16"
                                  Fill="#FF000000"
                                  Stretch="Uniform" HorizontalAlignment="Center"
                                  VerticalAlignment="Center"/>
                                                            </Grid>
                                                        </Grid>
                                                            
                                                </Grid>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsMouseOver" Value="True">
                                                        <Setter Property="Foreground" Value="{DynamicResource ModernButtonTextHover}" />
                                                        <Setter TargetName="ellipse" Property="Stroke" Value="{DynamicResource ModernButtonBorderHover}" />
                                                    </Trigger>
                                                    <Trigger Property="IsChecked" Value="True">
                                                        <Setter Property="Foreground" Value="{DynamicResource ModernButtonTextPressed}" />
                                                        <Setter TargetName="ellipse" Property="Stroke" Value="{DynamicResource ModernButtonBorderPressed}" />
                                                        <Setter TargetName="ellipse" Property="Fill" Value="{DynamicResource ModernButtonIconBackgroundPressed}" />
                                                        <Setter TargetName="icon" Property="Fill" Value="{DynamicResource ModernButtonIconForegroundPressed}" />
                                                    </Trigger>
                                                    <Trigger Property="IsEnabled" Value="false">
                                                        <Setter Property="Foreground" Value="{DynamicResource ModernButtonTextDisabled}" />
                                                        <Setter TargetName="ellipse" Property="Stroke" Value="{DynamicResource ModernButtonBorderDisabled}" />
                                                    </Trigger>
                                                    <Trigger Property="IsFocused" Value="true">
                                                        <Setter TargetName="ellipse" Property="Stroke" Value="{DynamicResource Accent}" />
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                    </Style>
                                   
                            </Grid.Resources>
                            <Grid x:Name="controlGrid">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBox
                                    x:Name="PART_TimeBox"
                                    Background="{TemplateBinding Background}"
                                    Foreground="{TemplateBinding Foreground}"
                                    Text="{Binding Value, StringFormat=t, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
                                    TextAlignment="{TemplateBinding TextAlignment}"
                                    IsReadOnly="{Binding IsValueReadOnly, RelativeSource={RelativeSource TemplatedParent}}" />
                                <ToggleButton x:Name="_timePickerToggleButton"
                                              Margin="2,0,0,0"
                                              Grid.Column="1"
                                              Focusable="False"
                                              Background="Transparent"
                                              BorderThickness="0"
                                              Style="{StaticResource ToggleButtonTemplate}"
                                              IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}}"
                                              IsHitTestVisible="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BoolToOppositeBoolConverter}}"/>
                                   
                            </Grid>
                            <Popup x:Name="PART_Popup"
                                   IsOpen="{Binding IsChecked, ElementName=_timePickerToggleButton}"
                                   StaysOpen="False">
                                <Border BorderThickness="1">
                                    <Grid>
                                        <ListBox x:Name="PART_TimeListItems"
                                                 BorderThickness="0"
                                                 Width="{Binding ElementName=controlGrid, Path=ActualWidth}"
                                                 Height="{Binding PopupHeight, RelativeSource={RelativeSource TemplatedParent}}"
                                                 DisplayMemberPath="Display"
                                                 ItemContainerStyle="{StaticResource TimeItemStyle}" />
                                    </Grid>
                                </Border>
                            </Popup>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- text-in-datagrid styles-->
    <Style x:Key="DataGridTextStyle" TargetType="TextBlock">
        <Setter Property="Margin" Value="2,0" />
    </Style>

    <Style x:Key="DataGridEditingTextStyle" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Padding" Value="0" />
    </Style>

    <Style x:Key="Heading1" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Segoe UI" />
        <Setter Property="FontSize" Value="30" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
    </Style>

    <Style x:Key="Heading2" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Segoe UI" />
        <Setter Property="FontSize" Value="16" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
    </Style>

    <Style x:Key="Title" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Segoe UI Light" />
        <Setter Property="FontSize" Value="23" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
    </Style>

    <Style x:Key="Small" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Segoe UI" />
        <Setter Property="FontSize" Value="{DynamicResource SmallFontSize}" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
    </Style>

    <Style x:Key="Emphasis" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Segoe UI" />
        <Setter Property="FontSize" Value="{DynamicResource SmallFontSize}" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
    </Style>

    <Style x:Key="Fixed" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="{DynamicResource FixedFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource FixedFontSize}" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
    </Style>
</ResourceDictionary>